﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_Edit_View_Shop : System.Web.UI.Page
{
    Funtion ft = new Funtion();
    public static int m_se = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        if(this.IsPostBack == false)
        {
            txtShopID.Text = ft.GetShopID();
            grvData.DataSource = ft.LoadShop();
            grvData.DataBind();
        }

    }
    protected void btnSummit_Click(object sender, EventArgs e)
    {
        if(ft.AddShop(ft.GetShopID(),txtUseShID.Text,txtLocation.Text,DateTime.Parse(txtStartDate.Text.Trim()),DateTime.Parse(txtEndDate.Text.Trim()),txtNotes.Text))
        {
            if (ft.AddShopDetail(ft.GetShopDID(), txtShopID.Text, txtLocation.Text))
            {
                txtShopID.Text = ft.GetShopID();
                txtUseShID.Text = null;
                txtStartDate.Text = null;
                txtEndDate.Text = null;
                txtLocation.Text = null;
                txtNotes.Text = null;
            }

        }
    }
    protected void btnSearch0_Click(object sender, EventArgs e)
    {
        if ("" != txtSearch.Text.Trim())
        {
            grvData.DataSource = ft.LoadShopByName(txtSearch.Text);
            grvData.DataBind();
            m_se = 1;
        }
        else
        {
            lblError1.Visible = true;
            lblError1.Text = "Enter Shop name";
        }
    }
    protected void grvIndex(object sender, GridViewPageEventArgs e)
    {
        grvData.PageIndex = e.NewPageIndex;
        if(0!=m_se)
        {
            grvData.DataSource = ft.LoadShopByName(txtSearch.Text);
            grvData.DataBind();
        }
        else
        {
            grvData.DataSource = ft.LoadShop();
            grvData.DataBind();
        }
    }
    protected void grvDataCancel(object sender, GridViewCancelEditEventArgs e)
    {
        grvData.EditIndex = -1;
        if (0 != m_se)
        {
            grvData.DataSource = ft.LoadShopByName(txtSearch.Text);
            grvData.DataBind();
        }
        else
        {
            grvData.DataSource = ft.LoadShop();
            grvData.DataBind();
        }
    }
    protected void grvDataEdit(object sender, GridViewEditEventArgs e)
    {
        grvData.EditIndex = e.NewEditIndex;
        if (0 != m_se)
        {
            grvData.DataSource = ft.LoadShopByName(txtSearch.Text);
            grvData.DataBind();
        }
        else
        {
            grvData.DataSource = ft.LoadShop();
            grvData.DataBind();
        }
    }
    protected void grvDataUpload(object sender, GridViewUpdateEventArgs e)
    {
        ft.UpdateShop(grvData.DataKeys[e.RowIndex].Value.ToString(), DateTime.Parse((grvData.Rows[e.RowIndex].Cells[4].Controls[0] as TextBox).Text), DateTime.Parse((grvData.Rows[e.RowIndex].Cells[5].Controls[0] as TextBox).Text), (grvData.Rows[e.RowIndex].Cells[6].Controls[0] as TextBox).Text);
        if (0 != m_se)
        {
            grvData.DataSource = ft.LoadShopByName(txtSearch.Text);
            grvData.DataBind();
        }
        else
        {
            grvData.DataSource = ft.LoadShop();
            grvData.DataBind();
        }
    }
}